package com.example.safeassistan.home.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.safeassistan.R;
import com.example.safeassistan.common.UserData;
import com.example.safeassistan.home.model.HomeCheckRecordModel;
import com.example.safeassistan.risk.model.RiskDetailCheckLogModel;

import java.util.List;

public class HomeCheckRecordFragmentAdapter extends BaseQuickAdapter<HomeCheckRecordModel.ResultDTO.RecordsDTO,BaseViewHolder> {
    public HomeCheckRecordFragmentAdapter(@Nullable List<HomeCheckRecordModel.ResultDTO.RecordsDTO> data) {
        super(R.layout.item_checkrecord, data);
    }

 @Override
    protected void convert(BaseViewHolder helper, HomeCheckRecordModel.ResultDTO.RecordsDTO item) {
     ImageView ivRiskLevel=helper.getView(R.id.ivRiskLevel);
     ImageView ivRiskImg=helper.getView(R.id.ivDevice);
     TextView tvCheckResult=helper.getView(R.id.tvCheckResult);

     Glide.with(mContext).load(item.getRiskPointImg())
             .placeholder(R.mipmap.default_image)
             .into(ivRiskImg);
        helper.setText(R.id.tvCreateTime,item.getCreateTime());
        helper.setText(R.id.tvCheckTitle,item.getRiskPointName());
        helper.setText(R.id.tvCheckPerson,item.getRealname());
        if (UserData.create(mContext).get(UserData.ls_jc).equals("1")){
            helper.getView(R.id.llAddress).setVisibility(View.VISIBLE);
            helper.setText(R.id.tvCheckAddress,"检查地址："+item.getCheckAddress());
        }else {
            helper.getView(R.id.llAddress).setVisibility(View.GONE);
        }
        helper.setText(R.id.tvChecktableName,item.getTableName());
        helper.setText(R.id.tvDepartName,"【"+(item.getDepartName()==null?"未知":item.getDepartName())+"】"+item.getCompanyName());

        if (item.getRiskLevel()!=null){
            switch (item.getRiskLevel()){
                case "1":
                    ivRiskLevel.setImageResource(R.mipmap.icon_shan_red_circle);
                    break;
                case "2":
                    ivRiskLevel.setImageResource(R.mipmap.icon_shan_orange_circle);
                    break;
                case "3":
                    ivRiskLevel.setImageResource(R.mipmap.icon_shan_yellow_circle);
                    break;
                case "4":
                    ivRiskLevel.setImageResource(R.mipmap.icon_shan_blue_circle);
                    break;
            }
        }

        //0通过 1不通过 2存在隐患 3不涉及 4 检查中
        switch (item.getTableResult()){
            case 3:
                helper.setText(R.id.tvCheckResult,"未涉及");
                tvCheckResult.setTextColor(mContext.getColor(R.color.blue_3B5BEA));
                tvCheckResult.setBackgroundResource(R.drawable.stoke_blue_bg);
                break;
            case 0:
                helper.setText(R.id.tvCheckResult,"已通过");
                tvCheckResult.setTextColor(mContext.getColor(R.color.green));
                tvCheckResult.setBackgroundResource(R.drawable.stoke_green_bg);
                break;
            case 1:
                helper.setText(R.id.tvCheckResult,"未通过");
                tvCheckResult.setTextColor(mContext.getColor(R.color.red));
                tvCheckResult.setBackgroundResource(R.drawable.stoke_red_bg);
                break;
            case 2:
                helper.setText(R.id.tvCheckResult,"存在隐患");
                tvCheckResult.setTextColor(mContext.getColor(R.color.orange));
                tvCheckResult.setBackgroundResource(R.drawable.stoke_orange_bg);
                break;
        }
 }
}